package com.ham.facade.impl;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ham.facade.ItemRatingReaderFacade;
import com.ham.model.ItemRatingModel;

public class ItemRatingCSVReaderFacadeImpl extends MainFacadeImpl implements
		ItemRatingReaderFacade {

	private static final Logger LOGGER = LoggerFactory
			.getLogger(ItemRatingCSVReaderFacadeImpl.class);

	@Override
	public List<ItemRatingModel> getItemList(String filePath)
			throws IOException {
		LOGGER.debug("Start processing " + filePath);
		String line = "";
		String separator = ",";
		List<ItemRatingModel> itemRatings = new ArrayList<ItemRatingModel>();
		BufferedReader br = new BufferedReader(new FileReader(filePath));
		while ((line = br.readLine()) != null) {
			String[] lines = line.split(separator);
			ItemRatingModel itemRating = new ItemRatingModel();
			itemRating.setItemId(lines[0]);
			itemRating.setRating(lines[1]);
			itemRating.setRatingDate(lines[2]);
			itemRatings.add(itemRating);
		}
		itemRatings.remove(0);
		return itemRatings;
	}

}
